package callnumber.gtdev5.com.photoVault.utils;

import android.content.Context;
import android.media.MediaPlayer;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;

import callnumber.gtdev5.com.photoVault.R;


/**
 * Created by cheng
 * PackageName FakeCall
 * 2018/6/11 10:28
 */

public class getDefaultRingutil {

    private static MediaPlayer mMediaPlayer;
//RingtoneManager.TYPE_NOTIFICATION;   通知声音

//RingtoneManager.TYPE_ALARM;  警告

//RingtoneManager.TYPE_RINGTONE; 铃声

    /**
     * 获取的是铃声的Uri
     * @param ctx
     * @param type
     * @return
     */
    public static Uri getDefaultRingtoneUri(Context ctx, int type) {

        return RingtoneManager.getActualDefaultRingtoneUri(ctx, type);

    }
    /**
     * 获取的是铃声相应的Ringtone
     * @param ctx
     * @param type
     */
    public Ringtone getDefaultRingtone(Context ctx, int type) {

        return RingtoneManager.getRingtone(ctx,
                RingtoneManager.getActualDefaultRingtoneUri(ctx, type));

    }

    /**
     * 播放铃声
     * @param ctx
     * @param type
     */
    public static void PlayRingTone(Context ctx,int type){
            if (MobileInfoUtils.getMobileType().equals("Xiaomi")){
                mMediaPlayer = MediaPlayer.create(ctx, R.raw.xiaomiring);
                mMediaPlayer.start();
            }else {
                mMediaPlayer = MediaPlayer.create(ctx,
                        getDefaultRingtoneUri(ctx,type));
                // mMediaPlayer.setLooping(true);
                try {
                    if (!mMediaPlayer.isPlaying()){
                        mMediaPlayer.start();
                    }
                }catch (NullPointerException e){
                    e.printStackTrace();
                }
            }






    }
    /**
     * 停止播放
     */
    public static void stopRing(){
        if (mMediaPlayer!=null){
            mMediaPlayer.stop();
        }
    }
}
